﻿var tmpFckEditer = "";
//隐藏窗口
function showhide(flag) {
    if (!flag) {
        $("#dialogFrame").dialog("close");
    }
}
function Show(sid) {
    if ($("#" + sid).is(":hidden")) {
        $("#" + sid).show();
    } else {
        $("#" + sid).hide();
    }
}
function ShowObj(sid,display) {
    if (display) {
        $("#" + sid).show();
    } else {
        $("#" + sid).hide();
    }
}
function DoNothing(sid,title) {
    if ($("#" + sid).is(":hidden")) {
        $("#" + sid).show();
        $("#" + sid).html(title);
        return true;
    }
    else {
        alert("正在操作中请不要重复，以免浪费不必要的资源！");
        return false;
    }
}


function OpenDialog(txt, url) {
    $("#dialogFrame").remove();
    var str = "<div id='dialogFrame'><iframe src='" + url + "' frameborder='0' marginwidth='0' marginheight='0' width='785' height='510'></iframe></div>";
    $("body").append(str);
    $("#dialogFrame").dialog({
        title: txt,
        autoOpen: true, 
        modal: true, 
        width: 800,
        height: 550,
        resizable: true,
        bgiframe: true
    });
}



function FileUpload(tid, title) {
    var delid = "";
    if ($("#" + tid).val().indexOf("=") > 0) {
        delid = $("#" + tid).val().split("=")[1];
    }
    //开始提交
    $("#form1").ajaxSubmit({
        beforeSubmit: function () {
            $("#out" + tid).hide();
            $("#bar" + tid).html("正在上传中请稍候...");
        },
        success: function (data) {
            if (data.success) {
                $("#" + tid).val(data.text);
                $("#bar" + tid).html("<a target='_blank' href='" + data.text + "'>预览</a>");
            } else {
                $("#bar" + tid).html(data.error);
            }
            $("#out" + tid).show();
        },
        url: "../Attachment/AttachAjax.aspx?a=add_attachment&fileid=file" + tid + "&title=" + title + "&delid=" + delid,
        type: "post",
        dataType: "json"
    });
}

function PopitImage(tid, title) {
    OpenDialog(title, '../Systems/UploadImage.aspx?h=500&t=text&s=parent.form1.' + tid);
}

function TipImage(tid, flag) {

    if (flag) {
        var txtpicvalue = $.trim($("#" + tid).val());
        var txtpicarr = txtpicvalue.split(',');
        var txtpicwidth = $("#" + tid).width() - 15;

        if (txtpicvalue != "NO") {
            var picscode = "";
            var tpicscount = 0;
            for (var i = 0; i < txtpicarr.length; i++) {
                var tmpxtpic = $.trim(txtpicarr[i]);
                var pic = new Image();
                pic.src = tmpxtpic;
                var picwidth = (pic.width <= 340) ? pic.width : 340;
                if (tmpxtpic != "") {
                    picscode += "<img src='" + tmpxtpic + "' width='" + picwidth + "' border='1px' />";
                    tpicscount++;
                }
            }
            if (tpicscount == 0) {
                $("#tip" + tid).html("您没有添加任何图片，多个图片用','分开！")
            }
            else {
                $("#tip" + tid).html(picscode + "<br />您已添加" + tpicscount + "副图片了，(共" + txtpicvalue.length + "个字符，多个图片用','分开！)");
            }
        }
        $("#tip" + tid).show().css({ "position": "absolute", "top": "28px", "left": "5px", "width": txtpicwidth + "px" });
    } else {
        $("#tip" + tid).hide();
    }

}

function FckInserImg(img) {
    var oEditor = FCKeditorAPI.GetInstance(tmpFckEditer);
    oEditor.InsertHtml(img);
}
function PopitFckUpload(vFckName) {
    tmpFckEditer = vFckName;
    OpenDialog('上传图片', '../Systems/UploadImage.aspx?t=func-obj&s=parent.FckInserImg');
}



function FckSetHtml(html) {
    var oEditor = FCKeditorAPI.GetInstance(tmpFckEditer);
    oEditor.SetHTML(html);
}
function FckGetHtml() {
    var oEditor = FCKeditorAPI.GetInstance(tmpFckEditer);
    return oEditor.GetXHTML(true);
}
function OpenBaiduEditer(vFckName) {
    tmpFckEditer = vFckName;
    window.open('/Tools/Editer/baidu/editer.html');
}




//管理页面
function CheckAll(form) {
    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];
        if (e.type == "checkbox") {
            if (e.name != "chkAll" && e.name != "isexact" && e.name != "showsql" && e.disabled == false)
                e.checked = form.chkAll.checked;
        }
    }
}
//管理页面
function SubmitUrl() {
    var andurl = "";
    if (arguments.length == 4) {
        andurl += "&t=" + arguments[0];
        andurl += "&id=" + arguments[1];
        andurl += "&" + arguments[0] + "=" + arguments[2];
        andurl += "&page=" + arguments[3];
    }
    andurl += "&ext_field=" + GetExtSearch(); 

    var no_list = $("#ddlMenu").val();
    var keyword = $("#keywords").val();
    var isexact = $("#isexact").attr("checked")? "1" : "0";
    document.location.href = "Admin.aspx?no_list=" + no_list + "&keyword=" + keyword + "&isexact=" + isexact  + andurl;
}
//管理页面
function SwapColor(obj, flag) {
    if (flag) {
        obj.style.backgroundColor = "#deeff9";
    }
    else {
        obj.style.backgroundColor = "#f4fbff";
    }
}
//管理页面
function LoadExtSearch() {
    var extstr= $.trim($("#hidExtField").val());
    if (extstr != "") {
        var extarr =extstr.split(",");
        for (i = 0; i < extarr.length; i++) {
            var iarr = extarr[i].split("|");
            for (j = 0; j < iarr.length; j++) {
                $("#ext_k_" + iarr[0]).attr("checked","true");
                $("#ext_v_" + iarr[0]).val(iarr[1]);
                $("#ext_t_" + iarr[0]).val(iarr[2]);
                $("#ext_c_" + iarr[0]).val(iarr[3]);
            }
        }
        ShowExtSearch();
    }
}
//管理页面
function GetExtSearch() {
    var telements = document.getElementById("form1").elements;
    var tlen=telements.length;
    var turl="";
    for (var i = 0; i < tlen; i++) {
        var tid = telements[i].id;
        if (tid.substr(0, 6) == "ext_k_") {
            if ($("#ext_k_" + tid.substr(6)).attr("checked")) {
                turl += "," + tid.substr(6) + "|" + $("#ext_v_" + tid.substr(6)).val() + "|" + $("#ext_t_" + tid.substr(6)).val() + "|" + $("#ext_c_" + tid.substr(6)).val();
            }
        }
    }
    if (turl != "") {
        turl= turl.substr(1);
    }
    return turl;
}
//管理页面
function ShowExtSearch() {
    if ($("#extsearch").is(":hidden")) {
        $("#extsearch").show();
        $("#extsenior").html("高级↑");
        return true;
    } else {
        $("#extsearch").hide();
        $("#extsenior").html("高级↓");
    }
}



/*
//初始化下拉列表
function InitDropDownList(channels, bindno_list, seleno_list) {
    var obj = document.getElementById("ddlMenu");
    var bindflag = true;
    var bindnum = 0;
    obj.options.length = 0;

    if (channels.length > 0) {
        for (var i = 0; i < channels.length; i++) {
            if (i == 0) {
                var tOption = new Option(channels[0].text, channels[0].value);
                obj.options.add(tOption);
            }
            if (bindno_list == "" || channels[i].value.indexOf(bindno_list) == 0) {
                var oOption = new Option(channels[i].text, channels[i].value);
                oOption.style.backgroundColor = channels[i].bgcolor;
                obj.options.add(oOption);
                if (bindflag && (seleno_list == "" || channels[i].value.indexOf(seleno_list) == 0)) {
                    obj.options[bindnum].selected = "selected";
                    bindflag = false;
                }
                bindnum++;
            }
        }
    }
}

<%=jsonString%>
function ChangeDropDownList() {
    var ddlobj = document.getElementById("ddlTables");
    var sarr = ddlobj.options[ddlobj.selectedIndex].value.split("-");
    if (sarr.length > 0) {
        InitDropDownList(jsonChannels, sarr[0], jsonSeleClslist);
    }
}
InitDropDownList(jsonChannels, jsonBindClslist, jsonSeleClslist);
*/
